﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DataAccess.Sys.BO;
using AMS.DataAccess.Sys.Interfaces;
using System.Text;

public partial class Security_EditRoleDlg :BaseWorkPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        action = Request.QueryString["op"];
        if (!IsPostBack)
        {
            if (action == "edit")
            {
            }
        }
    }

    string action;

    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (action == "add")
        {
            RoleInfo role = new RoleInfo();
            role.RoleName = txtRoleName.Text;

            IRoleManager roleMgr = ManagerFactory.CreateRoleManager();
            try
            {
                roleMgr.AddRole(CallContext, role);

                string json = "{id:" + role.AID.ToString() + ", name:'" + role.RoleName + "'}";
                StringBuilder sbscript = new StringBuilder();
                sbscript.Append("setTimeout(function(){window.parent.document.onDialogCallBack(1, 'succeed',");
                sbscript.Append(json);
                sbscript.Append(");}, 3000);");

                ClientScript.RegisterStartupScript(this.GetType(), "fdsafsa",
                    sbscript.ToString(),
                    true);

                lblMsg.Text = "添加成功，3秒钟后自动关闭对话框。";
                btnOK.Enabled = false;
            }
            catch (Exception ex)
            {
                lblMsg.Text = "添加失败！<br/>" + ex.ToString();
            }
        }
    }
}
